package com.yunkaweilai.android.view.dialog.room;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.utils.CornerUtils;
import com.flyco.dialog.widget.base.BaseDialog;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.activity.operation.consumption.room.RoomInfoActivity;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.constants.CommonConstants;
import com.yunkaweilai.android.model.Event;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.Utils;

import org.greenrobot.eventbus.EventBus;

/**
 * 房台关台
 * Created by Administrator on 2017/6/27.
 */

public class GuadanRoomCloseDialog extends BaseDialog<GuadanRoomCloseDialog> {

    TextView idTvDel;
    TextView idTvClose;
    private Context context = null;
    private ImageView idImgClose;
    private String type;
    private TextView idEdtTypeName;
    private TextView idEdtTypeName1;
    private String group_id;
    private String gid;
    private String content;
    private String content2;
    private TextView idTvType;

    public GuadanRoomCloseDialog(Context context, String group_id, String content, String gid) {
        super(context);
        this.content = content;
        this.context = context;
        this.group_id = group_id;
        this.gid = gid;

    }

    public GuadanRoomCloseDialog(Context context, String group_id, String content, String content2, String gid) {
        super(context);
        this.content = content;
        this.context = context;
        this.group_id = group_id;
        this.gid = gid;
        this.content2 = content2;

    }

    @Override
    public View onCreateView() {
        widthScale(0);
        //showAnim(new Swing());
        //dismissAnim(this, new ZoomOutExit());
        View inflate = View.inflate(mContext, R.layout.dialog_del_confirm, null);
        idTvDel = (TextView) inflate.findViewById(R.id.id_tv_del);
        idTvClose = (TextView) inflate.findViewById(R.id.id_tv_close);
        idImgClose = ((ImageView) inflate.findViewById(R.id.id_img_close));
        idEdtTypeName = ((TextView) inflate.findViewById(R.id.id_edt_type_name));
        idEdtTypeName1 = ((TextView) inflate.findViewById(R.id.id_edt_type_name1));
        idTvType = ((TextView) inflate.findViewById(R.id.id_tv_max_type));
        idTvType.setText("关台确认");
        idTvDel.setText("确认");
        idEdtTypeName.setText(content);
        if (content2 != null){
            idEdtTypeName1.setVisibility(View.VISIBLE);
            idEdtTypeName1.setText(content2);
        }else {
            idEdtTypeName1.setVisibility(View.GONE);
        }
            //设置背景颜色，和背景的透明圆弧角度
            inflate.setBackgroundDrawable(
                    CornerUtils.cornerDrawable(Color.parseColor("#f8f9fa"), dp2px(10)));

        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        idTvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        idTvDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initHttp();
            }
        });

    }

    private void initHttp() {
        HttpRequest.postUrl(Api.GUADAN_CLOST_FANGTAI)
                .addParams("group_id", group_id)
                .addParams("gid", gid)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mContext, json);
                        if (checkCode) {
                            dismiss();
                            EventBus.getDefault().post(new Event.TypeEvent(CommonConstants.GUADAN_ROOM_LIST_REFRESH, true));
                            ((RoomInfoActivity) mContext).finish();
                        }
                    }

                    @Override
                    public void onError(Exception e) {

                    }
                });
    }

}